#include <opencv2\core\core.hpp>
#include <opencv2\highgui\highgui.hpp>
#include <opencv2\imgproc\imgproc.hpp>
#include <iostream>
#include "myOpenCVLIB\myheader.h"

using namespace std;  
using namespace cv; 

Mat img, grayImg, dst, detectedEdges;

int edgeThresh = 1;
int lowThresh;
int const maxLowThresh = 100;

int ratio = 2;
const int maxRatio =5;

int kernelSize = 3;
const int maxKernelSize = 10;


const char * WINDOW_NAME = "CANNY EDGE DETECTOR";


void onChange(int, void*){
	
	blur(grayImg, detectedEdges, Size(3,3));

	Canny( detectedEdges, detectedEdges, lowThresh, lowThresh * ratio, kernelSize);

	imshow("Edges", detectedEdges);

	dst = Scalar::all(0);

	img.copyTo(dst, detectedEdges);
	imshow(WINDOW_NAME, dst);

}

int main(){

	img = imread(IMGS);
	if(!img.data){return -1;}

	dst.create(img.size(), img.type());

	cvtColor(img, grayImg, CV_BGR2GRAY);

	namedWindow(WINDOW_NAME);
	namedWindow("Edges");

	createTrackbar("min tresh:", WINDOW_NAME, &lowThresh,maxLowThresh,onChange);
	createTrackbar("ratio:", WINDOW_NAME, &ratio,maxRatio,onChange);
	//createTrackbar("kernel size:", WINDOW_NAME, &kernelSize,maxKernelSize,onChange);

	waitKey();

	return 0;
}